$(function () {
    $.ajax({
        type: "POST",
        url: baseURL + "sys/business/list",
		async:false,
        success: function(r){
            var jrorder = r.business.todayOrderNum;
            var zrorder = r.business.yesterdayOrderNum;
            var zongorder = r.business.totalOrderNum;
            var jrtrade = r.business.todayTradeVolume;
            var zrtrade = r.business.yesterdayTradeVolume;
            var zongtrade = r.business.totalTradeVolume;
            $("#jrorder").text(jrorder);
            $("#zrorder").text(zrorder);
            $("#jrtrade").text("￥"+jrtrade);
            $("#zrtrade").text("￥"+zrtrade);
            $("#jrbl").css("width",((jrorder/zongorder)*100+2)+"%");
            $("#zrbl").css("width",((zrorder/zongorder)*100+2)+"%");
            $("#jrjybl").css("width",((jrtrade/zongtrade)*100+2)+"%");
            $("#zrjybl").css("width",((zrtrade/zongtrade)*100+2)+"%");
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
            sheelvesid:null,
            reason:null,
            number:null

		},
		showList: true,
        showInfoList :true,
		title: null,
        shelvesstock: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
            vm.showInfoList = false;
			vm.shelvesstock = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.lowershelves.id == null ? "sys/lowershelves/save" : "sys/lowershelves/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.lowershelves),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "sys/lowershelves/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get(baseURL + "sys/lowershelves/info/"+id, function(r){
                vm.lowershelves = r.lowershelves;
            });
		},
		reload: function (event) {
			vm.showList = true;
			vm.showInfoList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});